package airthmetic.exercise.stack;

import java.util.Stack;

public class _155_最小栈MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;


    public _155_最小栈MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }


    public void push(int val) {
        stack.push(val);
        if(minStack.isEmpty() || val <= minStack.peek()){
            minStack.push(val);
        }
    }

    public void pop() {
        int pop = stack.pop();
        if (pop == minStack.peek()){
            minStack.pop();
        }
    }

    public int top() {
       return stack.peek();
    }

    public int getMin() {
       return minStack.peek();
    }


    public static void main(String[] args) {

    }
}
